<template>
<h3>员工列表练习</h3>
  <el-form style="width: 500px;margin: 0 auto" label-width="80px">
    <el-form-item label="姓名">
      <el-input placeholder="请输入姓名" v-model="emp.name"></el-input>
    </el-form-item>
    <el-form-item label="工资">
      <el-input placeholder="请输入工资" v-model="emp.salary"></el-input>
    </el-form-item>
    <el-form-item label="工作">
      <el-input placeholder="请输入工作" v-model="emp.job"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button @click="add()">添加</el-button>
    </el-form-item>
  </el-form>
  <el-table :data="arr">
    <el-table-column v-for="item in tableColumns" v-bind="item"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
const del = (i,emp)=>{
  if (confirm("您确认删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}
const tableColumns = ref([
  {type:'index',width:80,label:'编号'},
  {prop:'name',label:'姓名'},
  {prop:'salary',label:'工资'},
  {prop:'job',label:'工作'},
])
const emp = ref({name:"",salary:"",job:""});
const arr = ref([]);
const add = ()=>{
  arr.value.push({...emp.value});
}
</script>

<style scoped>

</style>